<?php

spl_autoload_unregister(array('YiiBase','autoload'));
Yii::import('application.vendors.google.autoload', true);
spl_autoload_register(array('YiiBase','autoload'));
use UnitedPrototype\GoogleAnalytics;


class Google
{
	public static $id = 'UA-40893853-1';
	public static $domain = 'pc2mobi.net';

	public static function trackLogin()
	{
		try
		{
			$tracker = new GoogleAnalytics\Tracker(self::$id, self::$domain);

			$campaign = new GoogleAnalytics\Campaign('direct');
			$utmz = new Utmz_cookie_parser();
			$campaign->setSource((!empty($utmz->utmz_source))?$utmz->utmz_source:'unknown');
			$campaign->setName((!empty($utmz->utmz_campaign))?$utmz->utmz_campaign:'unknown');
			$campaign->setMedium((!empty($utmz->utmz_medium))?$utmz->utmz_medium:'unknown');
			$campaign->setContent((!empty($utmz->utmz_content))?$utmz->utmz_content:'unknown');
			$tracker->setCampaign($campaign);

			$visitor = new GoogleAnalytics\Visitor();
			$visitor->setIpAddress($_SERVER["REMOTE_ADDR"]);
			$visitor->setUserAgent($_SERVER["HTTP_USER_AGENT"]);

			$session = new GoogleAnalytics\Session();

			$page = new GoogleAnalytics\Page("/_login");
			$page->setTitle("Авторизация");
			$page->setReferrer((isset($_SERVER["HTTP_REFERER"]))?$_SERVER["HTTP_REFERER"]:"unknown");
			$page->setCharset("UTF-8");

			$tracker->trackPageview($page, $session, $visitor);

			Yii::log("Авторизация", "info", "google");
		}
		catch (Exception $e)
		{
			Yii::log($e->getMessage(), "error", "google");
		}
	}
	
	public static function trackSendMessage()
	{
		try
		{
			$tracker = new GoogleAnalytics\Tracker(self::$id, self::$domain);

			$campaign = new GoogleAnalytics\Campaign('direct');
			$utmz = new Utmz_cookie_parser();
			$campaign->setSource((!empty($utmz->utmz_source))?$utmz->utmz_source:'unknown');
			$campaign->setName((!empty($utmz->utmz_campaign))?$utmz->utmz_campaign:'unknown');
			$campaign->setMedium((!empty($utmz->utmz_medium))?$utmz->utmz_medium:'unknown');
			$campaign->setContent((!empty($utmz->utmz_content))?$utmz->utmz_content:'unknown');
			$tracker->setCampaign($campaign);

			$visitor = new GoogleAnalytics\Visitor();
			$visitor->setIpAddress($_SERVER["REMOTE_ADDR"]);
			$visitor->setUserAgent($_SERVER["HTTP_USER_AGENT"]);

			$session = new GoogleAnalytics\Session();

			$page = new GoogleAnalytics\Page("/_sendMessage");
			$page->setTitle("Отправка сообщения");
			$page->setReferrer((isset($_SERVER["HTTP_REFERER"]))?$_SERVER["HTTP_REFERER"]:"unknown");
			$page->setCharset("UTF-8");

			$tracker->trackPageview($page, $session, $visitor);

			Yii::log("Отправлено сообщение", "info", "google");
		}
		catch (Exception $e)
		{
			Yii::log($e->getMessage(), "error", "google");
		}
	}
	
	public static function trackSendFile()
	{
		try
		{
			$tracker = new GoogleAnalytics\Tracker(self::$id, self::$domain);

			$campaign = new GoogleAnalytics\Campaign('direct');
			$utmz = new Utmz_cookie_parser();
			$campaign->setSource((!empty($utmz->utmz_source))?$utmz->utmz_source:'unknown');
			$campaign->setName((!empty($utmz->utmz_campaign))?$utmz->utmz_campaign:'unknown');
			$campaign->setMedium((!empty($utmz->utmz_medium))?$utmz->utmz_medium:'unknown');
			$campaign->setContent((!empty($utmz->utmz_content))?$utmz->utmz_content:'unknown');
			$tracker->setCampaign($campaign);

			$visitor = new GoogleAnalytics\Visitor();
			$visitor->setIpAddress($_SERVER["REMOTE_ADDR"]);
			$visitor->setUserAgent($_SERVER["HTTP_USER_AGENT"]);

			$session = new GoogleAnalytics\Session();

			$page = new GoogleAnalytics\Page("/_sendFile");
			$page->setTitle("Отправка файла");
			$page->setReferrer((isset($_SERVER["HTTP_REFERER"]))?$_SERVER["HTTP_REFERER"]:"unknown");
			$page->setCharset("UTF-8");

			$tracker->trackPageview($page, $session, $visitor);

			Yii::log("Отправлен файл", "info", "google");
		}
		catch (Exception $e)
		{
			Yii::log($e->getMessage(), "error", "google");
		}
	}
	
}

?>
